package com.oracle.lingshangejia.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.bean.OutSideBean;

import java.util.List;

public class OutSideTaskAdapter extends RecyclerView.Adapter<OutSideTaskAdapter.ViewHolder> {

    private Context context;
    private List<OutSideBean.DataBean> data;
    private OnItemClickListener onItemClickListener;
    public interface OnItemClickListener{
        void onItemClick(View view, int postion);
    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
    public OutSideTaskAdapter(Context context, List<OutSideBean.DataBean> data){
        this.data=data;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_out_side_task,null);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        viewHolder.tv_out_title.setText(data.get(i).getRwmc());
        //viewHolder.tv_out_date.setText(data.get(i).ge);
        viewHolder.tv_out_content.setText(data.get(i).getRwms());
        viewHolder.tv_out_sbdate.setText("结束时间:"+data.get(i).getStartTime());


            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClickListener!=null){
                         onItemClickListener.onItemClick(v,i);
                    }
                }
            });
    }

    @Override
    public int getItemCount() {
        return data!=null?data.size():0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_out_title;
        TextView tv_out_date;
        TextView tv_out_content;
        TextView tv_out_sbdate;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_out_title=itemView.findViewById(R.id.tv_out_title);
            tv_out_date=itemView.findViewById(R.id.tv_out_date);
            tv_out_content=itemView.findViewById(R.id.tv_out_content);
            tv_out_sbdate=itemView.findViewById(R.id.tv_out_sbdate);
        }
    }
}
